/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for ProductColorDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class ProductColorDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public ProductColorDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(ProductColorDO objProductColorDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Color", SqlDbType.NVarChar);
            Sqlparam.Value = objProductColorDO.Color;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Image", SqlDbType.NVarChar);
            Sqlparam.Value = objProductColorDO.Image;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(ProductColorDO objProductColorDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductColorID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.ProductColorID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Color", SqlDbType.NVarChar);
            Sqlparam.Value = objProductColorDO.Color;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Image", SqlDbType.NVarChar);
            Sqlparam.Value = objProductColorDO.Image;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(ProductColorDO objProductColorDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductColorID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.ProductColorID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public ProductColorDO Select(ProductColorDO objProductColorDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductColorID", SqlDbType.Int);
            Sqlparam.Value = objProductColorDO.ProductColorID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ProductColorID"]))
                    objProductColorDO.ProductColorID = Convert.ToInt32(dr["ProductColorID"]);
                if (!Convert.IsDBNull(dr["ProductID"]))
                    objProductColorDO.ProductID = Convert.ToInt32(dr["ProductID"]);
                if (!Convert.IsDBNull(dr["Color"]))
                    objProductColorDO.Color = Convert.ToString(dr["Color"]);
                if (!Convert.IsDBNull(dr["Image"]))
                    objProductColorDO.Image = Convert.ToString(dr["Image"]);
                if (!Convert.IsDBNull(dr["OrderID"]))
                    objProductColorDO.OrderID = Convert.ToInt32(dr["OrderID"]);

            }
            return objProductColorDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrProductColorDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    ProductColorDO objProductColorDO = new ProductColorDO();
                    if (!Convert.IsDBNull(dr["ProductColorID"]))
                        objProductColorDO.ProductColorID = Convert.ToInt32(dr["ProductColorID"]);
                    if (!Convert.IsDBNull(dr["ProductID"]))
                        objProductColorDO.ProductID = Convert.ToInt32(dr["ProductID"]);
                    if (!Convert.IsDBNull(dr["Color"]))
                        objProductColorDO.Color = Convert.ToString(dr["Color"]);
                    if (!Convert.IsDBNull(dr["Image"]))
                        objProductColorDO.Image = Convert.ToString(dr["Image"]);
                    if (!Convert.IsDBNull(dr["OrderID"]))
                        objProductColorDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                    arrProductColorDO.Add(objProductColorDO);
                }
            }
            return arrProductColorDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable GetByProduct(int productID)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spProductColor_GetByProduct";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = productID;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        #endregion

    }

}
